<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品系统</el-breadcrumb-item>
      <el-breadcrumb-item>类别管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">

      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            clearable
            size="small"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              size="small"
            ></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" size="small">添加类别</el-button>
        </el-col>
      </el-row>
      <el-table
        :data="categories"
        style="width: 100%">
        <el-table-column
          header-align="center"
          align="center"
          type="index"
          label="序号"
        >
        </el-table-column>
        <el-table-column
          prop="categoryName"
          label="类别名称"
          width="180">
        </el-table-column>
        <el-table-column
          prop="categoryLevel"
          label="类别层级"
          width="180">
        </el-table-column>
        <el-table-column
          prop="sort"
          label="排序"
          width="180">
        </el-table-column>
        <el-table-column
          align="center"
          label="是否显示">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.showStatus"
                       active-color="#13ce66"
                       inactive-color="#ff4949"
                       :active-value="1"
                       :inactive-value="0"
                       inactive-text="禁用"
                       active-text="正常"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          label="操作"
        >

          <template slot-scope="scope">
            <el-button type="danger" size="mini">删除</el-button>
            <el-button type="warning" size="mini">编辑</el-button>
            <el-button type="primary" size="mini" @click="selectChildren(scope.row.categoryId)">查看子类</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>

</template>

<script>
export default {
  name: "BzMallCategory",
  data(){
    return {
      categories:[]
    }
  },
  methods:{
    selectChildren(pid){
      this.axios.get(`/admin/bzCategory/childrenCategory/${pid}`)
        .then(resp=>{
          this.categories = resp.data.data;
        })
    }
  },
  created(){
    this.axios.get("/admin/bzCategory")
      .then(resp=>{
        this.categories = resp.data.data;
      })
  }
}
</script>

<style scoped>
  .el-card{
    margin-top:20px
  }
  .el-row{
    margin: 10px 0;
  }
</style>
